<template>
	<view class="unlock-photo-container">
		<!-- 自定义导航栏 -->
		<view class="custom-navbar">
			<view class="navbar-content">
				<view class="back-btn" @click="goBack">
					<text class="back-icon">‹</text>
				</view>
				<text class="navbar-title">解锁你喜欢的照片</text>
				<view class="placeholder"></view>
			</view>
		</view>

		<!-- 主图展示区域 -->
		<view class="photo-display-section">
			<view class="photo-container" @longpress="handleLongPress">
				<!-- 主图 -->
				<image :src="photoData.image" mode="aspectFill" class="main-photo"></image>
				
				<!-- 水印层 -->
				<view class="watermark-layer" v-if="!photoData.unlocked">
					<image src="/static/images/lvpai/1731754148198_.pic.jpg" mode="aspectFit" class="watermark-image"></image>
				</view>
			</view>
		</view>

		<!-- 促销提示横幅 -->
		<view class="promotion-banner">
			<view class="promotion-content">
				<text class="promotion-icon">🎉</text>
				<text class="promotion-text">玩多人合照写真，即可免费解锁1套单人写真！</text>
				<view class="go-play-btn" @click="goToGroupPhoto">
					<text class="go-play-text">去玩玩</text>
					<text class="arrow-icon">›</text>
				</view>
			</view>
		</view>

		<!-- 底部解锁区域 -->
		<view class="unlock-section">
			<view class="unlock-info">
				<view class="unlock-status">
					<text class="status-title">限时免费</text>
					<text class="status-subtitle">已选4张</text>
				</view>
				<view class="unlock-button" @click="unlockPhoto">
					<text class="unlock-text">解锁照片</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			photoData: {
				id: 1,
				image: '/static/images/lvpai/1521754111180_.pic_hd.jpg',
				unlocked: false,
				title: '霓虹夜色',
				cost: 10
			}
		}
	},
	onLoad(options) {
		// 接收传递的照片信息
		if (options.photoId) {
			this.loadPhotoData(options.photoId);
		}
		if (options.unlocked) {
			this.photoData.unlocked = options.unlocked === 'true';
		}
	},
	methods: {
		goBack() {
			uni.navigateBack();
		},
		
		loadPhotoData(photoId) {
			// 根据photoId加载照片数据
			console.log('加载照片数据:', photoId);
			// 这里可以从服务器或本地存储加载具体的照片数据
		},
		
		handleLongPress() {
			if (this.photoData.unlocked) {
				// 已解锁的照片可以保存
				uni.showActionSheet({
					itemList: ['保存到相册', '分享给朋友'],
					success: (res) => {
						if (res.tapIndex === 0) {
							this.savePhoto();
						} else if (res.tapIndex === 1) {
							this.sharePhoto();
						}
					}
				});
			} else {
				// 未解锁的照片不能保存
				uni.showToast({
					title: '请先解锁照片',
					icon: 'none',
					duration: 2000
				});
			}
		},
		
		savePhoto() {
			// 保存照片到相册
			uni.saveImageToPhotosAlbum({
				filePath: this.photoData.image,
				success: () => {
					uni.showToast({
						title: '保存成功！',
						icon: 'success'
					});
				},
				fail: () => {
					uni.showToast({
						title: '保存失败',
						icon: 'none'
					});
				}
			});
		},
		
		sharePhoto() {
			// 分享照片
			uni.share({
				provider: 'weixin',
				scene: 'WXSceneSession',
				type: 2,
				imageUrl: this.photoData.image,
				success: () => {
					uni.showToast({
						title: '分享成功！',
						icon: 'success'
					});
				}
			});
		},
		
		goToGroupPhoto() {
			// 跳转到多人合照页面
			uni.navigateTo({
				url: '/pages/group_photo/index'
			});
		},
		
		unlockPhoto() {
			if (this.photoData.unlocked) {
				uni.showToast({
					title: '照片已解锁',
					icon: 'none'
				});
				return;
			}
			
			uni.showModal({
				title: '解锁照片',
				content: `需要消耗 ${this.photoData.cost} 个算力值解锁这张照片，是否确认？`,
				confirmText: '确认解锁',
				cancelText: '取消',
				success: (res) => {
					if (res.confirm) {
						this.performUnlock();
					}
				}
			});
		},
		
		performUnlock() {
			uni.showLoading({
				title: '解锁中...'
			});
			
			// 模拟解锁过程
			setTimeout(() => {
				uni.hideLoading();
				this.photoData.unlocked = true;
				
				uni.showToast({
					title: '解锁成功！',
					icon: 'success',
					duration: 2000
				});
				
				// 触觉反馈
				uni.vibrateShort({
					type: 'light'
				});
			}, 1500);
		}
	}
}
</script>

<style scoped>
.unlock-photo-container {
	width: 100%;
	min-height: 100vh;
	background: #f8f9fa;
	display: flex;
	flex-direction: column;
}

/* 自定义导航栏 */
.custom-navbar {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	z-index: 1000;
	background: white;
	padding-top: var(--status-bar-height, 44rpx);
	border-bottom: 1rpx solid #eee;
}

.navbar-content {
	height: 88rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 30rpx;
}

.back-btn {
	width: 60rpx;
	height: 60rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}

.back-icon {
	font-size: 48rpx;
	color: #333;
	font-weight: 300;
}

.navbar-title {
	font-size: 36rpx;
	font-weight: 600;
	color: #333;
}

.placeholder {
	width: 60rpx;
}

/* 主图展示区域 */
.photo-display-section {
	margin-top: calc(88rpx + var(--status-bar-height, 44rpx));
	flex: 1;
	padding: 40rpx 30rpx 20rpx;
	display: flex;
	align-items: center;
	justify-content: center;
}

.photo-container {
	position: relative;
	width: 100%;
	max-width: 690rpx;
	height: 920rpx;
	border-radius: 20rpx;
	overflow: hidden;
	box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.15);
}

.main-photo {
	width: 100%;
	height: 100%;
	object-fit: cover;
}

/* 水印层 */
.watermark-layer {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	display: flex;
	align-items: center;
	justify-content: center;
	background: rgba(255, 255, 255, 0.1);
	pointer-events: none;
}

.watermark-image {
	width: 200rpx;
	height: 200rpx;
	opacity: 0.3;
	transform: rotate(-30deg);
}

/* 促销横幅 */
.promotion-banner {
	background: linear-gradient(135deg, #ff6b9d 0%, #ff8e8e 100%);
	margin: 20rpx 30rpx;
	border-radius: 16rpx;
	padding: 24rpx;
}

.promotion-content {
	display: flex;
	align-items: center;
	gap: 12rpx;
}

.promotion-icon {
	font-size: 32rpx;
}

.promotion-text {
	flex: 1;
	color: white;
	font-size: 28rpx;
	font-weight: 500;
}

.go-play-btn {
	display: flex;
	align-items: center;
	gap: 8rpx;
	background: rgba(255, 255, 255, 0.2);
	border-radius: 20rpx;
	padding: 12rpx 20rpx;
}

.go-play-text {
	color: white;
	font-size: 28rpx;
	font-weight: 600;
}

.arrow-icon {
	color: white;
	font-size: 24rpx;
}

/* 底部解锁区域 */
.unlock-section {
	background: white;
	padding: 30rpx;
	padding-bottom: calc(30rpx + env(safe-area-inset-bottom));
	border-top: 1rpx solid #eee;
}

.unlock-info {
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.unlock-status {
	flex: 1;
}

.status-title {
	font-size: 36rpx;
	font-weight: 700;
	color: #333;
	display: block;
	margin-bottom: 8rpx;
}

.status-subtitle {
	font-size: 28rpx;
	color: #999;
}

.unlock-button {
	background: linear-gradient(135deg, #ff6b9d 0%, #ff8e8e 100%);
	border-radius: 50rpx;
	padding: 28rpx 60rpx;
	min-width: 240rpx;
	display: flex;
	align-items: center;
	justify-content: center;
	box-shadow: 0 8rpx 24rpx rgba(255, 107, 157, 0.4);
	transition: all 0.3s ease;
}

.unlock-button:active {
	transform: translateY(2rpx) scale(0.98);
	box-shadow: 0 4rpx 16rpx rgba(255, 107, 157, 0.5);
}

.unlock-text {
	color: white;
	font-size: 32rpx;
	font-weight: 600;
	letter-spacing: 1rpx;
}

/* 响应式设计 */
@media (max-width: 750rpx) {
	.photo-container {
		height: 800rpx;
	}
	
	.promotion-text {
		font-size: 26rpx;
	}
	
	.unlock-button {
		padding: 24rpx 48rpx;
		min-width: 200rpx;
	}
	
	.unlock-text {
		font-size: 30rpx;
	}
}

/* 水印动画效果 */
@keyframes watermarkPulse {
	0%, 100% {
		opacity: 0.3;
	}
	50% {
		opacity: 0.5;
	}
}

.watermark-image {
	animation: watermarkPulse 3s ease-in-out infinite;
}
</style>
